const date = new Date();

function range(start, end) {
    const arr = [];
    for (let i = start; i <= end; i++) {
        arr.push(i);
    }
    return arr;
}
Page({
    data: {
        years: range(1980, date.getFullYear()),
        months: range(1, 12),
        days: range(1, 31),
        year: date.getFullYear(),
        month: 1,
        day: 1,
        value: [17, 5, 14],
        next: 1,
        active: false,
        sex: 'woman',
    },
    onLoad: function(options) {
        console.log(this.data.sex, this.data.active);
    },
    click() {
        if (!this.data.active) {
            this.setData({
                active: true,
                sex: 'man',
            });
        } else {
            this.setData({
                active: false,
                sex: 'woman',
            });
        }
        console.log(this.data.sex, this.data.active);
    },
    next() {
        if (this.data.next == '1') {
            this.setData({
                next: 2,
            });
            console.log(this.data.heightVal, this.data.sex);
        } else if (this.data.next == '2') {
            if (!this.data.date) {
                this.showMsg('请选择你的出生日期');
            } else {
                this.setData({
                    next: 3,
                });
            }
        } else if (this.data.next == '3') {
            console.log(this.data.heightVal, this.data.weightVal, this.data.sex, this.data.date);
            let year = this.data.date.substring(0, 4)
            var date = new Date();
            let year1 = date.getFullYear();
            let yearNum = year1 - year
            console.log(yearNum);
            tt.reLaunch({
                url: '/pages/keduResult/keduResult?age=' + yearNum +
                    '&height=' + this.data.heightVal +
                    '&weight=' + this.data.weightVal +
                    '&sex=' + this.data.sex
            });
        }
    },
    slideTrigger: function(e) {
        var that = this;
        that.setData({
            heightVal: e.detail.curVal,
        });
        // console.log('当前选择的值', e.detail.curVal);
    },
    slideTrigger1: function(e) {
        var that = this;
        that.setData({
            weightVal: e.detail.curVal,
        });
        // console.log('当前选择的值', e.detail.curVal);
    },
    bindChange(event) {
        const val = event.detail.value;
        this.setData({
            year: this.data.years[val[0]],
            month: this.data.months[val[1]],
            day: this.data.days[val[2]],
        });
        let date = this.data.year + '-' + this.data.month + '-' + this.data.day;
        this.setData({
            date: date
        });
    },
    showMsg(n) { // 轻提示方法
        tt.showToast({
            title: n,
            icon: "none"
        });
    },
});